import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useInvoiceStore = defineStore('invoice', () => {
  // 抽屉状态
  const drawerVisible = ref(false)
  
  // 当前操作类型 (add/edit/view)
  const operationType = ref<'add' | 'edit' | 'view'>('add')
  
  // 发票类型 (incoming/outgoing)
  const invoiceType = ref<'incoming' | 'outgoing'>('incoming')
  
  // 当前编辑的发票ID
  const currentInvoiceId = ref<string | number | null>(null)
  
  // 打开发票抽屉
  const openInvoiceDrawer = (type: 'incoming' | 'outgoing', op: 'add' | 'edit' | 'view', id?: string | number) => {
    invoiceType.value = type
    operationType.value = op
    currentInvoiceId.value = id || null
    drawerVisible.value = true
  }
  
  // 关闭发票抽屉
  const closeInvoiceDrawer = () => {
    drawerVisible.value = false
    currentInvoiceId.value = null
  }
  
  return {
    drawerVisible,
    operationType,
    invoiceType,
    currentInvoiceId,
    openInvoiceDrawer,
    closeInvoiceDrawer
  }
})